﻿/* 
 * Copyright 2010 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Ngilead.WCF
{
    /// <summary>
    /// Wrapper class encapsulating an object to Clone() or Merge()
    /// </summary>
    [DataContract]
    public class WrapperWCF
    {
        /// <summary>
        /// Target action enumeration
        /// </summary>
        public enum enumTargetAction
        {
            /// <summary>Clone</summary>
            Clone,
            /// <summary>Merge</summary>
            Merge
        };

        private enumTargetAction _action;
        private Object _value;

        /// <summary>
        /// Action
        /// </summary>
        [DataMember]
        public enumTargetAction Action
        {
            get { return _action; }
            set { _action = value; }
        }

        /// <summary>
        /// Value
        /// </summary>
        [DataMember]
        public Object Value
        {
            get { return _value; }
            set { _value = value; }
        }

        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="action">Action</param>
        /// <param name="value">value</param>
        public WrapperWCF(Object value, enumTargetAction action)
        {
            _action = action;
            _value = value;
        }

        #endregion

        /// <summary>
        /// Override ToString()
        /// </summary>
        /// <param name="other">Object</param>
        /// <returns>True/False</returns>
        public override bool Equals(object other)
        {
            if (_value == null)
                return (other == null);
            if (other == null)
                return false;
            return _value.Equals(other);
        }

        /// <summary>
        /// Override GetHashCode
        /// </summary>
        /// <returns>HashCode</returns>
        public override int GetHashCode()
        {
            if (_value == null)
                return 0;
            else
                return _value.GetHashCode();
        }


        /// <summary>
        /// Override ToString()
        /// </summary>
        /// <returns>WrapperWCF({Action}) : {Value.ToString()}</returns>
        public override string ToString()
        {
            if (_value == null)
            {
                return String.Empty;
            }
            return String.Format("WrapperWCF({0}) : {1}", _action.ToString(), (_value != null) ? _value.ToString() : String.Empty);
        }
    }
}
